package com.leoman.spinningmachine.tab1;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.leoman.helper.adapter.BaseRecyclerAdapter;
import com.leoman.helper.util.FrescoUtil;
import com.leoman.helper.util.StringUtil;
import com.leoman.spinningmachine.R;
import com.leoman.spinningmachine.bean.LeavespBean;
import com.leoman.spinningmachine.util.DateUtil;

import java.util.List;

/**
 * Created by Administrator on 2018-06-04.
 */

public class LeaveSpAdapter extends BaseRecyclerAdapter<LeavespBean> {

    private Context mContext;
    private onSpClick spListener;

    public LeaveSpAdapter(Context context, int layoutResId, List<LeavespBean> data) {
        super(layoutResId, data);
        this.mContext = context;
    }

    @Override
    protected void bindTheData(BaseViewHolder holder, LeavespBean bean, int position) {
        TextView tv_head = (TextView) holder.findViewById(R.id.tv_head);
        SimpleDraweeView iv_pic = (SimpleDraweeView) holder.findViewById(R.id.iv_pic);

        TextView tv_has_sp = (TextView) holder.findViewById(R.id.tv_has_sp);
        LinearLayout ll_no_sp = (LinearLayout) holder.findViewById(R.id.ll_no_sp);

        TextView tv_sp_user = (TextView) holder.findViewById(R.id.tv_sp_user);
        TextView tv_type = (TextView) holder.findViewById(R.id.tv_type);
        TextView tv_begin_time = (TextView) holder.findViewById(R.id.tv_begin_time);
        TextView tv_end_time = (TextView) holder.findViewById(R.id.tv_end_time);
        TextView tv_agree = (TextView) holder.findViewById(R.id.tv_agree);
        TextView tv_no_agree = (TextView) holder.findViewById(R.id.tv_no_agree);

        if (1 == bean.getStatus()) {
            ll_no_sp.setVisibility(View.VISIBLE);
            tv_has_sp.setVisibility(View.GONE);
        } else {
            ll_no_sp.setVisibility(View.GONE);
            tv_has_sp.setVisibility(View.VISIBLE);
            tv_has_sp.setText("" + bean.getStatusName());
        }

        tv_head.setText("" + DateUtil.getyMdHms(bean.getCreateDate(), "MM月dd日 HH:mm"));
        FrescoUtil.setImg(mContext, iv_pic, bean.getHeadImage());
        tv_sp_user.setText("" + bean.getReason());
        switch (bean.getTypeStatus()) {
            case 1:
                tv_type.setText("请假类型:出差");
                break;
            case 2:
                tv_type.setText("请假类型:事假");
                break;
            case 3:
                tv_type.setText("请假类型:调休");
                break;
            case 4:
                tv_type.setText("请假类型:病假");
                break;
            case 5:
                tv_type.setText("请假类型:产假");
                break;
            case 6:
                tv_type.setText("请假类型:陪产假");
                break;
            case 7:
                tv_type.setText("请假类型:婚假");
                break;
            case 8:
                tv_type.setText("请假类型:丧假");
                break;
            case 9:
                tv_type.setText("请假类型:其他");
                break;
        }
        tv_begin_time.setText("开始时间:" + DateUtil.getyMdHms(bean.getStartTime(), "yyyy-MM-dd HH:mm"));
        tv_end_time.setText("结束时间:" + DateUtil.getyMdHms(bean.getEndTime(), "yyyy-MM-dd HH:mm"));

        StringUtil.changeTextColor(tv_type, 0, 5, Color.parseColor("#9f9fa1"));
        StringUtil.changeTextColor(tv_begin_time, 0, 5, Color.parseColor("#9f9fa1"));
        StringUtil.changeTextColor(tv_end_time, 0, 5, Color.parseColor("#9f9fa1"));

        tv_agree.setTag(R.id.text1, bean);
        tv_agree.setTag(R.id.text2, position);
        tv_agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LeavespBean bean = (LeavespBean) v.getTag(R.id.text1);
                int position = (int) v.getTag(R.id.text2);
                if (spListener != null) {
                    spListener.sp(bean.getLeaveId(), position, 2);
                }
            }
        });

        tv_no_agree.setTag(R.id.text1, bean);
        tv_no_agree.setTag(R.id.text2, position);
        tv_no_agree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LeavespBean bean = (LeavespBean) v.getTag(R.id.text1);
                int position = (int) v.getTag(R.id.text2);
                if (spListener != null) {
                    spListener.sp(bean.getLeaveId(), position, 3);
                }
            }
        });
    }

    interface onSpClick {
        void sp(int id, int position, int type);
    }

    public void setSpClick(onSpClick listener) {
        this.spListener = listener;
    }
}
